using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
    /// <summary>
    /// Controller class for CommercialLog
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class CommercialLogController
    {
        // Preload our schema..
        CommercialLog thisSchemaLoad = new CommercialLog();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public CommercialLogCollection FetchAll()
        {
            CommercialLogCollection coll = new CommercialLogCollection();
            Query qry = new Query(CommercialLog.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public CommercialLogCollection FetchByID(object CommercialLogID)
        {
            CommercialLogCollection coll = new CommercialLogCollection().Where("CommercialLogID", CommercialLogID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public CommercialLogCollection FetchByQuery(Query qry)
        {
            CommercialLogCollection coll = new CommercialLogCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object CommercialLogID)
        {
            return (CommercialLog.Delete(CommercialLogID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object CommercialLogID)
        {
            return (CommercialLog.Destroy(CommercialLogID) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(byte? CountryID,DateTime? RFDate,int? TimeStart,int? TimeEnd,string TimeStartFormatted,string TimeEndFormatted,int? Duration,string Typology,decimal? NominalCost,decimal? RealCost,decimal? EquivalentCost,byte? PositionInBreak,byte? NumberOfSpotsInBreak,byte? TypeOfSpot,int? TypeOfBuyCode,int? MediaCode,int? ProgramCode,int? ProductID,int? ProdVersionID,int? CategoryID,int? SectorID,int? SubSectorID,int? SubSector2ID,int? BrandID,int? AdvertiserID,int? AgencyID,DateTime DateAdded,DateTime DateModified)
	    {
		    CommercialLog item = new CommercialLog();
		    
            item.CountryID = CountryID;
            
            item.RFDate = RFDate;
            
            item.TimeStart = TimeStart;
            
            item.TimeEnd = TimeEnd;
            
            item.TimeStartFormatted = TimeStartFormatted;
            
            item.TimeEndFormatted = TimeEndFormatted;
            
            item.Duration = Duration;
            
            item.Typology = Typology;
            
            item.NominalCost = NominalCost;
            
            item.RealCost = RealCost;
            
            item.EquivalentCost = EquivalentCost;
            
            item.PositionInBreak = PositionInBreak;
            
            item.NumberOfSpotsInBreak = NumberOfSpotsInBreak;
            
            item.TypeOfSpot = TypeOfSpot;
            
            item.TypeOfBuyCode = TypeOfBuyCode;
            
            item.MediaCode = MediaCode;
            
            item.ProgramCode = ProgramCode;
            
            item.ProductID = ProductID;
            
            item.ProdVersionID = ProdVersionID;
            
            item.CategoryID = CategoryID;
            
            item.SectorID = SectorID;
            
            item.SubSectorID = SubSectorID;
            
            item.SubSector2ID = SubSector2ID;
            
            item.BrandID = BrandID;
            
            item.AdvertiserID = AdvertiserID;
            
            item.AgencyID = AgencyID;
            
            item.DateAdded = DateAdded;
            
            item.DateModified = DateModified;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(long CommercialLogID,byte? CountryID,DateTime? RFDate,int? TimeStart,int? TimeEnd,string TimeStartFormatted,string TimeEndFormatted,int? Duration,string Typology,decimal? NominalCost,decimal? RealCost,decimal? EquivalentCost,byte? PositionInBreak,byte? NumberOfSpotsInBreak,byte? TypeOfSpot,int? TypeOfBuyCode,int? MediaCode,int? ProgramCode,int? ProductID,int? ProdVersionID,int? CategoryID,int? SectorID,int? SubSectorID,int? SubSector2ID,int? BrandID,int? AdvertiserID,int? AgencyID,DateTime DateAdded,DateTime DateModified)
	    {
		    CommercialLog item = new CommercialLog();
		    
				item.CommercialLogID = CommercialLogID;
				
				item.CountryID = CountryID;
				
				item.RFDate = RFDate;
				
				item.TimeStart = TimeStart;
				
				item.TimeEnd = TimeEnd;
				
				item.TimeStartFormatted = TimeStartFormatted;
				
				item.TimeEndFormatted = TimeEndFormatted;
				
				item.Duration = Duration;
				
				item.Typology = Typology;
				
				item.NominalCost = NominalCost;
				
				item.RealCost = RealCost;
				
				item.EquivalentCost = EquivalentCost;
				
				item.PositionInBreak = PositionInBreak;
				
				item.NumberOfSpotsInBreak = NumberOfSpotsInBreak;
				
				item.TypeOfSpot = TypeOfSpot;
				
				item.TypeOfBuyCode = TypeOfBuyCode;
				
				item.MediaCode = MediaCode;
				
				item.ProgramCode = ProgramCode;
				
				item.ProductID = ProductID;
				
				item.ProdVersionID = ProdVersionID;
				
				item.CategoryID = CategoryID;
				
				item.SectorID = SectorID;
				
				item.SubSectorID = SubSectorID;
				
				item.SubSector2ID = SubSector2ID;
				
				item.BrandID = BrandID;
				
				item.AdvertiserID = AdvertiserID;
				
				item.AgencyID = AgencyID;
				
				item.DateAdded = DateAdded;
				
				item.DateModified = DateModified;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

